<?php

namespace app\index\controller;

use think\Controller;

class Wallet extends Base {
	public function index() {
		$data = model ( 'Wallet' )->getAll ( array ([ 'user_id','=',$this->uid ] ) );
		$this->assign ( 'data', $data );
		return $this->fetch ();
	}
	function add() {
		if ($this->request->isPost ()) {
			$paypwd = $this->request->param ( 'paypwd' );
			if ($paypwd != $this->member ['paypwd'])
				echo json_encode ( array ('code' => 0,'msg' => lang ( 'paypwd_error' ) ) );
			else {
				$data ['user_id'] = $this->uid;
				$data ['type'] = $this->request->param ( 'type' );
				$data ['address'] = $this->request->param ( 'address' );
				$data ['create_time'] = time ();
				$log = model ( 'Wallet' )->add ( $data );
				if ($log > 0)
					echo json_encode ( array ('code' => 99,'msg' => lang ( 'success' ) ) );
				else
					echo json_encode ( array ('code' => 0,'msg' => lang ( 'fail' ) ) );
			}
		} else
			return $this->fetch ();
	}
	function del() {
		if ($this->request->isPost ()) {
			$paypwd = $this->request->param ( 'paypwd' );
			if ($paypwd != $this->member ['paypwd'])
				echo json_encode ( array ('code' => 0,'msg' => lang ( 'paypwd_error' ) ) );
			else {
				$map [] = [ 'user_id','=',$this->uid ];
				$map [] = [ 'id','=',$this->request->param ( 'id' ) ];
				$log = model ( 'Wallet' )->del ( $map );
				if ($log > 0)
					echo json_encode ( array ('code' => 99,'msg' => lang ( 'success' ) ) );
				else
					echo json_encode ( array ('code' => 0,'msg' => lang ( 'fail' ) ) );
			}
		}
	}
}
